package com.telecomyt.jwportal.map;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.TextView;

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.telecomyt.jwportal.MainActivity;
import com.telecomyt.jwportal.R;
import com.telecomyt.jwportal.base.BaseActivity;
import com.telecomyt.jwportal.base.BasePresenter;
import com.telecomyt.jwportal.utils.ToastUtils;

import java.util.Map;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MapActivity extends BaseActivity {


    @BindView(R.id.mtvMap)
    TextView mtvMap;
    private BottomSheetDialog bottomSheetDialog;
    private BottomSheetBehavior<View> mDialogBehavior;

    public static void start(Context context) {
        Intent starter = new Intent(context, MapActivity.class);
        context.startActivity(starter);
    }

    private boolean isClickStutas = true;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_map;
    }

    @Override
    protected void initView() {
        showSheetDialog();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected BasePresenter creatPresenter() {
        return null;
    }


    @OnClick(R.id.mtvMap)
    public void onViewClicked() {
        if (!isClickStutas) {
            bottomSheetDialog.dismiss();
            isClickStutas = true;
        } else {
            bottomSheetDialog.show();
            isClickStutas = false;

        }


    }


    private void showSheetDialog() {
        View view = View.inflate(MapActivity.this, R.layout.dialog_bottomsheet, null);
        bottomSheetDialog = new BottomSheetDialog(MapActivity.this, R.style.DialogStyle);
        bottomSheetDialog.setContentView(view);
        mDialogBehavior = BottomSheetBehavior.from((View) view.getParent());
        TextView mTvGaoDe = view.findViewById(R.id.mTvGaoDe);
        TextView mTvBaiDu = view.findViewById(R.id.mTvBaiDu);
        TextView mTvCancel = view.findViewById(R.id.mTvCancel);

        mTvGaoDe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("高德");
            }
        });

        mTvBaiDu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("百度");
            }
        });

        mTvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("取消");
            }
        });

        mDialogBehavior.setPeekHeight(getWindowHeight());//dialog的高度
        mDialogBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View view, int i) {
                if (i == BottomSheetBehavior.STATE_HIDDEN) {
                    bottomSheetDialog.dismiss();
                    mDialogBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                }
            }

            @Override
            public void onSlide(@NonNull View view, float v) {

            }
        });


    }

    private int getWindowHeight() {
        Resources res = MapActivity.this.getResources();
        DisplayMetrics displayMetrics = res.getDisplayMetrics();
        return displayMetrics.heightPixels;
    }


}
